package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.third.bairong.BairongCreditScore12ScoreData;
import com.ucredit.babel.common.model.third.bairong.BairongCreditScore12ScoreDataDetail;
import com.ucredit.babel.common.model.third.bairong.BairongUserCustomizeCreditScore12Data;
import com.ucredit.babel.common.model.third.bairong.BairongUserCustomizeCreditScore12Record;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/*
 * 百融-客制化评分12
 *
 * @author:guoqiang
 * */

public class BairongUserCustomizeCreditScore12Parse extends ParseBase{
    private Text val = new Text();
    private Text key = new Text();

    /**
     * @param context
     * @param model
     * @param successful
     * @return
     * @throws IOException
     * @throws InterruptedException
     */

    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        BairongUserCustomizeCreditScore12Record brRecord = (BairongUserCustomizeCreditScore12Record) model;
        BairongUserCustomizeCreditScore12Data brData = brRecord.getData();
        StringBuilder sb = getBaseInfo(brRecord, successful);
        StringBuilder brSb = new StringBuilder(2000);
        brSb.append(brData.getCode() == null ? "" : brData.getCode()).append(CRT001);
        brSb.append(brData.getSwiftNumber() == null ? "" : brData.getSwiftNumber()).append(CRT001);
        brSb.append(brData.getFlag().getScore() == null ? "" : brData.getFlag().getScore()).append(CRT001);
        brSb.append(brData.getFlag().getScoreData() == null ? "" : brData.getFlag().getScoreData()).append(CRT001);
        brSb.append(brData.getScore().getScorecust12() == null ? "" : brData.getScore().getScorecust12()).append(CRT001);

        BairongCreditScore12ScoreData score12ScoreData = brData.getScoreData();
        if(score12ScoreData != null){
            BairongCreditScore12ScoreDataDetail score12ScoreDataDetail = score12ScoreData.getScorecust12();
            if(score12ScoreDataDetail != null){
                brSb.append(score12ScoreDataDetail.getHqCellM12Orgnum() == null ? "" : score12ScoreDataDetail.getHqCellM12Orgnum()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getHqCellAllnum() == null ? "" : score12ScoreDataDetail.getHqCellAllnum()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getHqCellM1Allnum() == null ? "" : score12ScoreDataDetail.getHqCellM1Allnum()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getHqCellM1Orgnum() == null ? "" : score12ScoreDataDetail.getHqCellM1Orgnum()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getHqCellM12Allnum() == null ? "" : score12ScoreDataDetail.getHqCellM12Allnum()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getHqFlowclass() == null ? "" : score12ScoreDataDetail.getHqFlowclass()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getHqCellLstInteday() == null ? "" : score12ScoreDataDetail.getHqCellLstInteday()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getHqCapitalclass() == null ? "" : score12ScoreDataDetail.getHqCapitalclass()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getHqCellOrgnum() == null ? "" : score12ScoreDataDetail.getHqCellOrgnum()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getHqCreditlevel() == null ? "" : score12ScoreDataDetail.getHqCreditlevel()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getHqCellFstInteday() == null ? "" : score12ScoreDataDetail.getHqCellFstInteday()).append(CRT001);
            } else {
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
            }
        }else{
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
        }


        key.set(getKey());
        val.set((sb.toString() + brSb.toString()).replace("\n", " ").replace("\r", " "));
        context.write(key, val);

        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_br_user_customize_credit_score12_record_inc";
    }

    @Override
    public String getType() {
        return RecordType.BAIRONG_USER_CUSTOMIZE_CREDIT_SCORE12_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "百融-客制化评分12";
    }
}
